﻿using System;
using System.Collections;
using System.Collections.Generic;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using DotNetNuke.Services.Tokens;

namespace WESNet.DNN.Modules.UserExport
{
    public class MultiObjectTokenReplace : TokenReplace
    {
        public MultiObjectTokenReplace (Scope accessLevel, string language, PortalSettings portalSettings, UserInfo user, int moduleID, Dictionary<string, object> objectDictionary  ) : 
           base(accessLevel, language, portalSettings, user, moduleID)
        {
            foreach (var kvp in objectDictionary)
            {
                if (kvp.Value is IDictionary)
                {
                    PropertySource[kvp.Key] = new DictionaryPropertyAccess((IDictionary)kvp.Value);
                }
                else if (kvp.Value is IPropertyAccess)
                {
                    PropertySource[kvp.Key] = (IPropertyAccess)kvp.Value;
                }
                else
                {
                    PropertySource[kvp.Key] = new PropertyAccess(kvp.Value);
                }
            }
        }

        public string ReplaceEnvironmentalTokens(string sourceText)
        {
            return base.ReplaceEnvironmentTokens(sourceText);
        }
    }
}